/**
 * 简单的Token阅读器
 */
class SimpleTokenReader {
  constructor(tokens) {
    this.tokens = tokens
    // 指針
    this.index = 0
  }

  read() {
    if (this.index < this.tokens.length) {
      return this.tokens[this.index++]
    }
    return null
  }

  peek() {
    if (this.index < this.tokens.length) {
      return this.tokens[this.index]
    }
    return null
  }

  unread() {
    if (this.index > 0) {
      this.index--
    }
  }

  getPosition() {
    return this.index
  }

  setPosition(pos) {
    if (pos >= 0 && pos < this.tokens.length) {
      this.index = pos
    }
  }
}

module.exports = SimpleTokenReader